package LeetCode;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Code155_MinStack {

    Stack<List<Integer>> stack;

    public Code155_MinStack() {
        this.stack = new Stack<>();

    }

    public void push(int x) {
        List<Integer> list = new ArrayList<>(2);
        list.add(x);
        if (!stack.isEmpty()){
            list.add(x <= stack.peek().get(1) ? x : stack.peek().get(1));
        } else {
            list.add(x);
        }
        stack.push(list);
    }

    public void pop() {
        stack.pop();
    }

    public int top(){
        if (!stack.isEmpty()){
            return stack.peek().get(0);
        }
        return Integer.MIN_VALUE;
    }

    public int getMin() {
        if (!stack.isEmpty()){
            return stack.peek().get(1);
        }
        return Integer.MIN_VALUE;
    }
}
